home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 4
/
Precision Software Applications Silver Collection Volume 4 (1993).iso
/
stats
/
chadyn.exe
/
YCOMDE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-28
|
6KB
|
226 lines
/******************************* YCOMDE.C *********************************/
/***************** Differential Equation COMMANDS AND MENU *******************/
/********************* (C) 1986,7,8 by JAMES A. YORKE ************************/
#include "yinclud.h"
/* includes invert() */
static int(*savePlotPointer) () = NULL;
int DECommands(CodeName)
register char *CodeName;
{
int st;
int connectp(); /* needed for pointers */
int plot(), euler(), rungekutta(), iterate_map();
/* needed for pointers */
TEST2("conn", "connect") {
plotFlag = YES;
if(SCREEN)
PRINT "Now connects dots with lines. \n");
savePlotPointer = plotPointer;
plotPointer = connectp;
return(1);
}
TEST2("dis", "disconnect") {
plotFlag = 0;
if(SCREEN)
PRINT "Now plots disconnected dots. \n");
if(savePlotPointer != 0L)
plotPointer = savePlotPointer;
savePlotPointer = 0L;
return(1);
}
TEST("e") {
if(step != -9999.) {
PRINT
" E: computes single step error every 5 steps; (toggle); currently");
ODEcheck = 1 - ODEcheck;
toggle(ODEcheck);/* prints " ON\n" or " OFF\n" */
return(1);
}
}
TEST("euler") {
IterIteratee = euler;
return(1);
}
TEST2("v", "invert") {
invert();
return(1);
}
TEST("runge") {
IterIteratee = rungekutta;
return(1);
}
TEST("step") {
step = Entervalue(step, CHECKSET);
sixth_step = step / 6.; /* for rungekutta */
halfstep = step / 2;
return(1);
}
TEST("spc") {
if(steps_per_cycle != -9999) {
if(SCREEN) {
PRINT
"\n");
PRINT
"This is the number of differential equation steps in one period of the \n");
PRINT
"of the forcing period.\n");
PRINT
" ******IT MUST NOT BE SMALL******* \n");
PRINT
"The larger the value, the more accurate the solution.\n\n");
PRINT
"See command \"IPP\" (in menu \"P\") to change the plotting frequency.\n\n");
}
st = steps_per_cycle;
steps_per_cycle = Entervalue(steps_per_cycle, CHECKSET);
step = (twopi / C4) / steps_per_cycle;
sixth_step = step / 6.;/* for rungekutta */
halfstep = step / 2;
if(its_per_plot == st)
its_per_plot = steps_per_cycle;
if(steps_per_cycle < 10 &&
steps_per_cycle > -10)
PRINT
"WARNING: THIS IS PROBABLY TOO SMALL. YOU NEED LOTS OF STEPS PER CYCLE. \n\n");
}
else {
erase_line();
PRINT "Improper category for this map \n");
}
return(1);
}
return(0);
}
DEMenu() {
if(level == SETPARAM)
scr_clr(); /* in desmets pcio.a */
scr_rowcol(0, 2);
PRINT
" DIFFERENTIAL EQUATION MENU \n\n");
if(steps_per_cycle == -9999.&& step == -9999.)
PRINT
" The current process is not a differential equation\n\n\n");
PRINT
" CONN: CONNects consecutive dots as plotted with a line segment \n");
PRINT
" DIS: DISconnect turns off CONNECT; plots dots, not line segments \n\n\n");
if(step != -9999.) {
if(steps_per_cycle == -9999.)
PRINT
" STEP: Step size for differential equation = %g \n", step);
if(steps_per_cycle != -9999)
PRINT
" SPC: Steps_Per_Cycle(dif eq) %lf \n", steps_per_cycle);
PRINT
" EULER: Euler first order differential equation solver, fixed step size \n");
PRINT
" RUNGE: Runge-Kutta differential equation solver, 4th order, fixed step \n");
PRINT
" E: computes single step error every 5 steps; (toggle); currently");
toggle(ODEcheck);/* prints " ON\n" or " OFF\n" */
if(max_error > 0)
PRINT "maximum dif equ error = %11.8le \n", max_error);
PRINT "\n");
}
PRINT
" I: inverts differential equations and the Henon map\n");
return;
}
int invert() { /* 'v' inverts henon: map x ->
rho - x*x + C1*y inverse -y/C1 ->
rho/(C1**2) -(-y/C1)**2 +(-x/C1)/C1 */
int i;
if(strcmp("h", MapName) == 0
|| strcmp("H", MapName) == 0) {/* if map == henon */
if(C1 == 0) {
PRINT "YOU CANNOT INVERT THIS BECAUSE C1 = 0 \n");
return(NO);
}
if(level >= PROCESS) {
turnoff(BIGCROSS);
turnoff(SMALLCROSS);
}
X_lower = -X_lower / C1;
Y_lower = -Y_lower / C1;
X_upper = -X_upper / C1;
Y_upper = -Y_upper / C1;
flipHenon(y);
flipHenon(ya);
flipHenon(yb);
flipHenon(yc);
flipHenon(yd);
flipHenon(ye);
for(i = 0; i < 8; i++)/* y1,... y8 */
flipHenon(y + eqn0 + i * eqn1);
rho = rho / (C1 * C1);
C1 = 1 / C1;
X_coord = 1 - X_coord;
Y_coord = 1 - Y_coord;
setXYPlot();
ScreenConstants();/* defines ax,bx where x = 0,00,1,2 */
PRINT
"\n\n Map inverted; rho = %g; Jacobian C1 = %g\n"
,rho, C1);
PRINT
"X_coord=%d; Y_coord=%d \n", X_coord, Y_coord);
return(YES);
}
else
if(step != -9999.) {/* if we have a differential equation */
step = -step;
halfstep = -halfstep;
sixth_step = -sixth_step;
if(step < 0.)
PRINT
"INVERSE PROCESS: time step = %g \n", step);
else
PRINT
"NOW BACK WITH DIRECT PROCESS: time step = %g \n"
,step);
return(YES);
}
PRINT
"THIS ROUTINE(invert) DOES NOT HAVE THE INVERSE AVAILABLE. ABORT COMMAND\n\n"
);
return(NO);
}
flipHenon(yy)
double *yy;
{
double temp;
if(*yy == -9999.)
return;
temp = -yy[0] / C1;
yy[0] = -yy[1] / C1;
yy[1] = temp;
}